const GET = 'get';
const POST = 'post';
const PUT = 'put';
const DELETE = 'del';


//const baseURL = 'https://newlook.dianjingkeji.net/prod-api';
const baseURL = 'http://192.168.1.4:8077';


module.exports = function (options) {
  return new Promise (function (resolve,reject){
    let header = {
      'content-type':'application/json'
    };
    wx.request({
      url:baseURL + options.url,
      method: options.method,
      data:options.data,
      header:options.header,
      success(res){
        if(res.data.code ==401){
          wx.showToast({
            title: '请先登录',
            icon:'error',
            duration:2000
          })
          wx.redirectTo({
            url: '/pages/login/login',
          })
        }else{
          wx.showLoading ({
            title: '加载中...',
            success: function() {
              resolve(res.data)
           }
          })
        }
      },
      fail:function(err){
        reject(err)
        wx.showToast({
            title: '网络繁忙，请稍后重试~',
            icon: 'none'
        })
      },
      complete: function () {
        // 配对使用（loading消失）
         wx.hideLoading();
      }
    })
  })
}